package com.yuan.provider.service.impl;

import com.yuan.common.entity.UserAddress;
import com.yuan.common.service.UserService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@DubboService
@Component
public class UserServiceImpl implements UserService {


    @Override
    public List<UserAddress> getUserAddressList(String userId) {
        UserAddress address1 = new UserAddress(1, 1, "李老师", "北京市昌平区", "010-56253825");
        UserAddress address2 = new UserAddress(2, 1, "李老师", "上海市浦东新区", "010-56253825");
        List<UserAddress> list = new ArrayList<UserAddress>() {{
            add(address1);
            add(address2);
        }};
        List<UserAddress> userAddressList =
                list.stream().filter(userAddress -> userAddress.getUserId() == Integer.parseInt(userId)).collect(Collectors.toList());
        return userAddressList;
    }

    @Override
    public UserAddress getById(Integer id) {
        UserAddress address1 = new UserAddress(1, 1, "李老师", "北京市昌平区", "010-56253825");
        UserAddress address2 = new UserAddress(2, 1, "李老师", "上海市浦东新区", "010-56253825");
        List<UserAddress> list = new ArrayList<UserAddress>() {{
            add(address1);
            add(address2);
        }};
        return list.stream().filter(userAddress -> userAddress.getId() == id).collect(Collectors.toList()).get(0);
    }
}
